package edu.hrbu.spring.controller;

import edu.hrbu.spring.pojo.Dept;
import edu.hrbu.spring.service.DeptService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 徐登宇
 */
@RequestMapping("/dept")
@Controller
public class DeptController {

    @Resource(name = "deptServiceImpl")
    DeptService deptService;

    @RequestMapping("/list")
    public String list(Model model) {
        System.out.println("list....");
        List<Dept> deptList = deptService.getAllDept();
        model.addAttribute("deptList", deptList);
        return "dept/list";
    }

    @RequestMapping("/save")
    public String save(Dept dept) {
        System.out.println("@@@dept===>" + dept);
        deptService.save(dept);
        return "forward:list";
    }

    @RequestMapping("/to/save")
    public String toSave() {
        return "dept/add";
    }

    @RequestMapping("/")
    public String protal() {
        return "forward:list";
    }

}
